#include "List.h"
//==================================================
void ListCreate(NODE **pListHead, NODE **pListEnd, char (*pIcon)[3])
{
	if(NULL == pIcon)
	{
		return;
	}
	
	NODE *pNew = new NODE;

	pNew->pLast = NULL;
	pNew->pNext = NULL;

	int i = 0;

	while(i<3)
	{
		pNew->Text[i][0]=pIcon[i][0];
		pNew->Text[i][1]=pIcon[i][1];
		pNew->Text[i][2]=pIcon[i][2];

		i++;
	}

	if(NULL == *pListHead && NULL == *pListEnd)
	{
		*pListHead = pNew;
		*pListEnd = pNew;
	}
	else
	{
		pNew->pLast = *pListEnd;
		(*pListEnd)->pNext = pNew;
		*pListEnd = pNew;
	}
}
//==================================================
void ListClear(NODE **pListHead, NODE **pListEnd)
{
	if(NULL != *pListHead)
	{
		NODE *pTemp = *pListHead;

		while(NULL != *pListHead)
		{
			pTemp = *pListHead;
			*pListHead = (*pListHead)->pNext;
			delete pTemp;
		}

		*pListHead = NULL;
		*pListEnd = NULL;
	}
}
//==================================================
void NodeDelete(NODE **pListHead, NODE **pListEnd, NODE *pNode)
{
	NODE *pTemp = pNode;

	if(NULL != pListHead && NULL != pListEnd && NULL != pNode)
	{
		if(NULL == pNode->pLast && NULL == pNode->pNext)
		{
			*pListHead = NULL;
			*pListEnd = NULL;

			delete pTemp;

			return;
		}
		else if(NULL == pNode->pLast && NULL != pNode->pNext)
		{
			*pListHead = (*pListHead)->pNext;
			(*pListHead)->pLast = NULL;

			delete pTemp;

			return;
		}
		else if(NULL != pNode->pLast && NULL != pNode->pNext)
		{
			pTemp->pLast->pNext = pTemp->pNext;
			pTemp->pNext->pLast = pTemp->pLast;

			delete pTemp;

			return;
		}
		else if(NULL != pNode->pLast && NULL == pNode->pNext)
		{
			*pListEnd = pTemp->pLast;
			(*pListEnd)->pNext = NULL;

			delete pTemp;

			return;
		}
	}
}
//==================================================
void NodeTextModify(NODE *pNode, char (*pIcon)[3])
{
	if(NULL != pNode)
	{
		int i = 0;

		while(i<3)
		{
			pNode->Text[i][0]=pIcon[i][0];
			pNode->Text[i][1]=pIcon[i][1];
			pNode->Text[i][2]=pIcon[i][2];
			i++;
		}
	}
}
//==================================================
void SaveLastStatus(NODE *pNode)
{
	if(NULL != pNode)
	{
		int i = 0;

		while(i<3)
		{
			pNode->LText[i][0] = pNode->Text[i][0];
			pNode->LText[i][1] = pNode->Text[i][1];
			pNode->LText[i][2] = pNode->Text[i][2];
			i++;
		}

		pNode->nLX = pNode->nX;
		pNode->nLY = pNode->nY;
	}
}
